package org.syh.boyangfighthealthclub.controller;

import org.syh.boyangfighthealthclub.entity.User;
import org.syh.boyangfighthealthclub.service.IUserService;
import org.syh.boyangfighthealthclub.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: Ben
 * @Date: 2021/3/10 18:28
 */
@WebServlet("/admin/updateUser")
public class UpdateUser extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        res.setContentType("text/html;utf-8");
        Integer id=Integer.parseInt(req.getParameter("id"));
        String nickname=req.getParameter("nickName");
        String userName=req.getParameter("userName");
        String password=req.getParameter("password");
        String email=req.getParameter("email");
        String sex=req.getParameter("sex");
        Integer age= Integer.valueOf(req.getParameter("age"));
        if ("".equals(nickname) || "".equals(userName) || "".equals(password) || "".equals(email) || "".equals(sex)) {
            res.sendRedirect("../fail.jsp");
        }
        IUserService iUserService=new UserServiceImpl();
        boolean judgment=iUserService.updateUser(new User(id,nickname,userName,password,email,sex,age,"用户"));
        if (judgment){
            res.sendRedirect("../success.jsp");
        }
    }
}
